//
//  TestSafeAreaViewController.m
//  testApp
//
//  Created by iMac on 2018/2/10.
//  Copyright © 2018年 iMac. All rights reserved.
//

#import "TestSafeAreaViewController.h"

NSString *text = @"曾经多少次在内心想着，如果有来世，我一定要与你好好好相爱一次，手牵手走完一生，就我们，不让任何人参与！来个两小无猜，或是青梅竹马，一开始和最后，都只有我们，不再把心交给任何人，把最好的都留给你，曾经多少次在内心幻想，如果时光可以倒流，我一定要再次紧紧地抓住你的手，不让你从我指尖流逝‘……只许你一世温柔！再也不将心轻易地给了任何人……";
#define screenWidth [UIScreen mainScreen].bounds.size.width
#define screenHeight [UIScreen mainScreen].bounds.size.height
#define navHeight self.navigationController.navigationBar.frame.size.height
#define statusBarHeight [UIApplication sharedApplication].statusBarFrame.size.height

@interface TestSafeAreaViewController ()

@end

@implementation TestSafeAreaViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    [self demo1_two];
}



/// 对demo1 进行一些优化
/* 在自定义的view中
 override func layoutSubviews() {
 super.layoutSubviews()
    if #available(iOS 11.0, *) {
        label.frame = safeAreaLayoutGuide.layoutFrame
    }
 }
 */
/// 对demo1 进行一些优化
// 使用frame 和 safeAreaInset
- (void)demo1_two {
    UIEdgeInsets inset;
    if (@available(iOS 11.0, *)) {
        inset = [UIApplication sharedApplication].delegate.window.safeAreaInsets;
    } else {
        inset = UIEdgeInsetsZero;
    }
    UILabel * lable1 = [[UILabel alloc] init];
    UILabel * lable2 = [[UILabel alloc] init];
    lable1.text = text;
    lable2.text = text;
    lable1.numberOfLines = 0;
    lable2.numberOfLines = 0;
    lable1.backgroundColor = [UIColor orangeColor];
    lable2.backgroundColor = [UIColor orangeColor];
    lable1.frame = CGRectMake(inset.left,
                              inset.top,
                              screenWidth - inset.left - inset.right,
                              200);
    lable2.frame = CGRectMake(inset.left,
                              screenHeight - inset.bottom - 200,
                              screenWidth - inset.left - inset.right,
                              200);
    [self.view addSubview:lable1];
    [self.view addSubview:lable2];
}

- (void)demo1 {
    UILabel * lable1 = [[UILabel alloc] init];
    UILabel * lable2 = [[UILabel alloc] init];
    lable1.text = text;
    lable2.text = text;
    lable1.numberOfLines = 0;
    lable2.numberOfLines = 0;
    lable1.backgroundColor = [UIColor orangeColor];
    lable2.backgroundColor = [UIColor orangeColor];
    lable1.frame = CGRectMake(0, 0, screenWidth, 200);
    lable2.frame = CGRectMake(0, screenHeight - 200, screenWidth, 200);
    [self.view addSubview:lable1];
    [self.view addSubview:lable2];
}

@end
